#pragma once
#define _WIN32_WINNT    0x0500
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#include <mswsock.h>

#include "nb_msg.h"
#include "nb_request.h"
#include "nb_response.h"
#include "nb_session.h"
#include "nb_handle.h"

class NB_Server
{
public:
	NB_Server(int nPort);
	~NB_Server();

public:
	void SetMaxConnections(int nMaxConnections);
	void SetRecvThreads( int nThreads );
	void SetMaxHandleThreads( int nMaxThreads );
	void SetSessionStart(lpfnSession);
	void SetSessionHandle(lpfnSession);
	void SetSessionClose(lpfnSession);
	void Run();

private:
	static DWORD WINAPI AcceptThread(LPVOID lParam);
	static DWORD WINAPI ServerThread(LPVOID lParam);

private:
	int				m_nPort;
	HANDLE			m_hCompletionPort;
	SOCKET			m_sListen;
	DWORD			m_nServerThreadsNum;
	bool			m_bShutdown;
	int				m_nRecvThreads;
	int				m_nMaxHandleThreads;
	int				m_nMaxConnections;

	NB_MsgManager*	m_pMsgManager;
	NB_Request *	m_pRequest;
	NB_Response*	m_pResponse;
	NB_Handle *		m_pHandle;

	CALL_BACK		m_CallBack;
};